/**
 * @param {number[]} nums1
 * @param {number[]} nums2
 * @return {number}
 */
var findMedianSortedArrays = function (nums1, nums2) {
  let num;
  const nums = [...nums1, ...nums2].sort((a, b) => a - b)
  if (nums.length % 2 === 0) {
    const one = nums[Math.floor((nums.length - 1) / 2)];
    const two = nums[Math.floor((nums.length + 1) / 2)];
    num = (one + two) / 2;
  } else {
    num = nums[Math.floor(nums.length / 2)]
  }
  return num;
};

nums1 = [1, 2], nums2 = [3, 4]

console.log(findMedianSortedArrays(nums1, nums2));